package cn.org.xiaosheng.okhttp.interceptor;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author XiaoSheng
 * @date 2023-11-23
 * @dec 描述
 */
@Slf4j
public class EncryptInterceptor implements Interceptor {

    private static final String TAG = "EncrypInterceptor";

    @Override
    public Response intercept(Chain chain) throws IOException {
        log.info("拦截被调用了!");
        Request originRequest = chain.request();
        Request.Builder requestBuilder = originRequest.newBuilder(); // 建立新的构建者
        // 将旧请求的请求方法和请求体设置到新请求中
        requestBuilder.method(originRequest.method(), originRequest.body());
        // 添加请求头
        Request request = requestBuilder
                .header("Authorization", "Bearer test1")
                .header("client-type", "web")
                .header("Conten-Type", "x-www-form-urlencoded")
                .header("tenant-id", "1")
                .build();
        // 向责任链后面传递
        return chain.proceed(request);
    }
}
